In the short lesson, we'll take a look at the very simple power monitor module power monitor allowing
us to respond to events such as the user's machine going to sleep or suspending and waking up or resuming.
It also provides us a number of platform specific events, like the computer being attached to an AC
power source running on battery or even being shut down.
I'll demonstrate the first two universal events suspend and resume before I do.
However, note that with this module, the module itself can only be required once the app is ready,
meaning we'll have to take a slightly different approach to requiring it.
I'll start by referencing the electron library on its own.
Const electron equals using this require electron and then requiring the individual modules from that
electron constant.
So with a structure we can now use the power monitor module directly from electron.
Once the app is ready, try requiring it any earlier and it won't work.
Electron dot power monitor.
On suspend, meaning the computers put to sleep pass a callback with the standard event object in which
we can now do any important tasks, like, for example, saving some data just before the computer goes
to sleep, which I'll just log out then using a second listener.
This time for the resume event, meaning the computer woke up, I'll check if my window still exists
and if not created, there's really only being applicable to Mac if no main window, meaning it's been
set to null call create window.
Same thing as the activate event save.
I'll close this window, not quitting the app, just closing the main window, then put my computer
to sleep.
Wake it back up.
And my window is recreated with the log from when I put it to sleep in the terminal, saving some data.
So a very simple module, but worth knowing.